package com.ventas.autopartes.database.user;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

//import com.mysql.jdbc.PreparedStatement;
import java.sql.PreparedStatement;

public class TestConnection {
	private static final String INSERT_XML = "INSERT INTO xml_data (NAME,SPEC) VALUES (?,?)";
	
	private static final String INPUT_FILE_PATH="c:\\borrar\\250.xml";
	private static final String FILE_NAME="XML_250";
	
	private static final String URL="jdbc:mysql://localhost:3306/"; //$NON-NLS-1$
	private static final String DB_NAME="xml_project"; //"XML_PROJECT";
	private static final String DRIVER_NAME="org.gjt.mm.mysql.Driver";
	private static final String USER_NAME="root";
	private static final String PASSWORD= "860523";

	public static void main(String[] args) throws Exception{
		Connection con = null;
		Statement stmt = null;
		PreparedStatement preparedStatement =null;
		//PreparedStatement p;
		try {
			Class.forName(DRIVER_NAME).newInstance();
			con = DriverManager.getConnection(URL + DB_NAME, USER_NAME, PASSWORD);
			//stmt = con.createStatement();
			
			InputStream input = new FileInputStream(INPUT_FILE_PATH);
			File fileIn = new File(INPUT_FILE_PATH);
			
			preparedStatement=con.prepareStatement(INSERT_XML);
			preparedStatement.setString(1, FILE_NAME);
			preparedStatement.setBinaryStream (2, input,(int)fileIn.length());
			
			preparedStatement.executeUpdate();
			
			preparedStatement.close();
			con.close();
			
		} catch (Exception e) {
			System.out.println("(Class)TestConnection - (ErrorType)SQLException");
			e.printStackTrace();
			con.rollback();
		}finally{
			if(preparedStatement!=null){
				preparedStatement.close();
				preparedStatement=null;
			}
			if(con!=null){
				con.close();
				con=null;
			}
		}
		
	}
	
}
